package com.wuuxiang.polestar.admin.service.property;

import java.util.List;

import org.apache.curator.utils.ZKPaths;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wuuxiang.polestar.admin.dao.IPropertyDao;
import com.wuuxiang.polestar.comm.constant.Constant;

/**
 * 项目名称：polestar <br>
 * 类描述： <br>
 * 创建人：夏鸿鹏 <br>
 * 创建时间：2017-11-28 14:53 <br>
 * 修改备注： <br>
 */
@Component
public class PropertyService implements IPropertyService {

	@Autowired
	private IPropertyDao propertyDao;

	@Override
	public Boolean checkExists(String teamName, String name) {
		return propertyDao.checkExists(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_NODE, teamName, name));
	}

	@Override
	public void createProperty(String teamName, String name, String value) {
		propertyDao.createProperty(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_NODE, teamName, name), "");
		propertyDao.createProperty(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_REMARK_NODE, teamName, name),
				"");
	}

	@Override
	public void removeProperty(String teamName, String name) {
		propertyDao.deleteProperty(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_NODE, teamName, name));
		propertyDao.deleteProperty(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_REMARK_NODE, teamName, name));
	}

	@Override
	public List<String> getPropertyLst(String teamName) {
		return propertyDao.listChildren(ZKPaths.makePath(Constant.ROOT_NODE, Constant.CONFIG_NODE, teamName));
	}
}
